package com.byxy.mysystem.model.testUser;

import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class TestCityCascaderDTO {

    private String value;
    private String label;
    private List<TestCityCascaderDTO> children;

    public static TestCityCascaderDTO build(TestCity testCity){
        TestCityCascaderDTO testCityCascaderDTO = new TestCityCascaderDTO();
        testCityCascaderDTO.setValue(testCity.getArea());
        testCityCascaderDTO.setLabel(testCity.getArea());
        if(!CollectionUtils.isEmpty(testCity.getChildren())){
            testCityCascaderDTO.setChildren(buildList(testCity.getChildren()));
        }
        return testCityCascaderDTO;
    }

    public static List<TestCityCascaderDTO> buildList(List<TestCity> list){
        List<TestCityCascaderDTO> testCityCascaderDTOList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (TestCity item:list) {
                testCityCascaderDTOList.add(build(item));
            }
        }
        return testCityCascaderDTOList;
    }
}
